﻿/***************************************************************************************/
// Author                 - Balaji Venkatesan
// Student ID             - 12527079
// Version                - 1.0
// CodeName               - Northodyne Solutions
// Module                 - E-Business Technologies
// Date                   - 12-September-2011
/***************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class AdminChangePassword : System.Web.UI.Page
{

    public string _connStr = "Initial Catalog=DBNorthodyneSolutions; Data Source=ABC\\SQLExpress;Trusted_Connection=Yes";
    public string _userName = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {

        //_userName = Session["UserName"].ToString();
        //lblUserName.Text = _userName;

        Label lblwelcome = (Label)Master.FindControl("lblWelcome");
        Label lblusername = (Label)Master.FindControl("lblUserName");
        Label lblexpression = (Label)Master.FindControl("lblExpression");
        HyperLink hyplogin = (HyperLink)Master.FindControl("hyplogin");
        lblwelcome.Visible = false;
        lblusername.Visible = false;
        lblexpression.Visible = false;
        hyplogin.Visible = false;

    }

    protected void btnChangePassword_Click(object sender, EventArgs e)
    {
        using (SqlConnection connection = new SqlConnection(_connStr))
        {
            connection.Open();
            string updateAgentPassword = "UPDATE Tb_Login SET Password = @Password WHERE UserName = @UserName";

            using (SqlCommand updateAgentCmd = new SqlCommand(updateAgentPassword, connection))
            {
                SqlParameter[] agentPrms = new SqlParameter[2];
                agentPrms[0] = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
                agentPrms[0].SqlValue = txtPassword.Text;

                agentPrms[1] = new SqlParameter("@UserName", SqlDbType.NVarChar, 50);
                agentPrms[1].SqlValue = txtUserName.Text;

                updateAgentCmd.Parameters.AddRange(agentPrms);
                updateAgentCmd.ExecuteNonQuery();
            }

            connection.Close();
        }

        Response.Redirect("Home.aspx");
    }
    protected void btnHome_Click(object sender, EventArgs e)
    {
        Response.Redirect("Home.aspx");
    }
}